package com.hx.yupao.once;

import com.alibaba.excel.EasyExcel;

import java.util.List;

/**
 * 导入Excel
 */
public class ImportExcel {

    public static void main(String[] args) {
        // 写法1：JDK8+ ,不用额外写一个DemoDataListener
        // since: 3.0.0-beta1
        String fileName = "E:\\java_project_files\\yupiProject\\matchpartner\\yupao-backend\\src\\main\\resources\\testExcel.xlsx";
        readByListener(fileName);
        synchronousRead(fileName);
    }

    public static void readByListener(String fileName) {
        // 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行
        // 具体需要返回多少行可以在`PageReadListener`的构造函数设置
        EasyExcel.read(fileName, XingQiuTableUserInfo.class, new TableListener()).sheet().doRead();

    }

    public static void synchronousRead(String fileName) {
        List<XingQiuTableUserInfo> totalDataList = EasyExcel.read(fileName).head(XingQiuTableUserInfo.class).sheet().doReadSync();
        for (XingQiuTableUserInfo xingQiuTableUserInfo : totalDataList) {
            System.out.println(xingQiuTableUserInfo);
        }
    }

}
